Passed
Pull Request — master (#75)
by Mathieu
01:41
created

DeleteEventAction.index   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 9
c 0
b 0
f 0
rs 9.95
cc 2
1
import {
2
  Delete,
3
  Controller,
4
  Inject,
5
  BadRequestException,
6
  UseGuards,
7
  Param,
8
  HttpCode
9
} from '@nestjs/common';
10
import {AuthGuard} from '@nestjs/passport';
11
import {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger';
12
import {ICommandBus} from 'src/Application/ICommandBus';
13
import {LoggedUser} from 'src/Infrastructure/User/Decorator/LoggedUser';
14
import {User} from 'src/Domain/User/User.entity';
15
import {DeleteEventCommand} from 'src/Application/FairCalendar/Command/DeleteEventCommand';
16
import {DeleteEventDTO} from './DTO/DeleteEventDTO';
17
18
@Controller('events')
19
@ApiUseTags('Event')
20
@ApiBearerAuth()
21
@UseGuards(AuthGuard('bearer'))
22
export class DeleteEventAction {
23
  constructor(
24
    @Inject('ICommandBus')
25
    private readonly commandBus: ICommandBus
26
  ) {}
27
28
  @Delete(':id')
29
  @ApiOperation({title: 'Delete an event'})
30
  @HttpCode(204)
31
  public async index(@Param() dto: DeleteEventDTO, @LoggedUser() user: User) {
32
    try {
33
      await this.commandBus.execute(new DeleteEventCommand(dto.id, user));
34
    } catch (e) {
35
      throw new BadRequestException(e.message);
36
    }
37
  }
38
}
39